package kr.hkit.powerjava.chapter22.work2.dao;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import kr.hkit.powerjava.chapter22.work2.vo.Department;

public class DepartmentManagerImpl implements ItemDaoInterface<Department> {
	private ArrayList<Department> arList;
	
	public DepartmentManagerImpl(ArrayList<Department> arList) {
		super();
		this.arList = arList;
	}

	@Override
	public void addItem(Department item) {//추가
		arList.add(item);
		
	}

	@Override
	public void delItem(Department item) {//삭제
		arList.remove(item);
		
	}

	@Override
	public void updateItem(Department item) {
		if(searchItem(item)){
			arList.set(arList.indexOf(item),item);
			}else{
				System.out.println("수정 실패");
			}
	}

	@Override//존재하냐 존재하지 않느냐?
	public boolean searchItem(Department item) {
		Department dept= null;
		return arList.contains(item);
	}

	@Override
	public void prnItems() {
		prnHeader();
		for(Department dept:arList){
			System.out.println(dept);
		}
		System.out.println();
	}

	private void prnHeader() {
		String str= String.format("%3s\t%5s\t%3s",
					"학번", "학과명", "층수");
		System.out.println(str);
		
	}
	@Override
	public void prnItems(Comparator<Department> comp) {
		Collections.sort(arList, comp);
		prnItems();
	}

}
